<?php
namespace App\Http\Controllers\Passenger\V2\Order;

use App\Enum\ActivityEnum;
use App\Http\Controllers\Controller;
use App\Models\Orders;
use App\Services\PassengerActivityService;
use App\Services\PassengerCommentService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class CommentController extends Controller
{


    /**
     * 发表评论
     */
    public function create(Request $request, PassengerCommentService $service)
    {

        $id    = $request->post('id', 0);
        $score = $request->post('score', 0);

        if(!$id || !in_array($score, [1,2,3,4,5]))
            return $this->sendError('参数不合法');

        $order_info = Orders::query()->where('status', '5')->find($id);
        if(!$order_info || $order_info->user_id != Auth::id())
            return $this->sendError('订单ID有误');

        //发放优惠券
        if(PassengerActivityService::checkGrantActivityCoupon(Auth::id(), ActivityEnum::ActivityFirstOrderId)==false)
            PassengerActivityService::grantActivityCoupon(Auth::id(), ActivityEnum::ActivityFirstOrderId);

        $service->create($order_info, $score);

        return $this->sendSuccess();
    }



}
